package Servlets;

import PackDatos.GestionBD;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class srv_comboCurso extends HttpServlet {

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        
        String pagina=null;
        ArrayList<Map> lstCursos = new ArrayList<Map>();
        HttpSession session = request.getSession(true);
        Connection cn = null;
        try {
            pagina = request.getParameter("pagina");
            // conectamos la BD 
            GestionBD og = new GestionBD();
            cn = og.conectar();
            // obtenemos los profesores
            String query = "select distinct c.id_curso,cur_nombre from curso c inner join nota n on n.id_curso = c.id_curso where cur_estado='1'";
            Statement stm = cn.createStatement();
            ResultSet rs = stm.executeQuery(query);
            
            while (rs.next()) {
                Map rec = new HashMap();
                rec.put("id_curso", rs.getInt("id_curso"));
                rec.put("cur_nombre", rs.getString("cur_nombre"));
                lstCursos.add(rec);
            }
            session.setAttribute("curMat",lstCursos);
            request.setAttribute("mensaje", " ");
            stm.close();
            cn.close();
        } catch (Exception e) {
            System.out.println("Error: ");
        }
        RequestDispatcher rd = request.getRequestDispatcher(pagina);
        rd.forward(request, response);
    }
}
